# ==================== 邮件=====================
import smtplib
from email.mime.text import MIMEText
# email 用于构建邮件内容
from email.header import Header
import os
import socket


try: 
    s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) 
    s.connect(('8.8.8.8',80)) 
    ip = s.getsockname()[0] 
finally: 
    s.close() 
# =============================================
def Send_email(to_addr, email_msg, header):
    # 发信方的信息：发信邮箱，邮箱授权码
    from_addr = ''
    password = ''
    # 发信服务器
    smtp_server = 'smtp.qq.com'
    # 邮箱正文内容，第一个参数为内容，第二个参数为格式(plain 为纯文本)，第三个参数为编码
    msg = MIMEText(email_msg, 'plain', 'utf-8')

    # 邮件头信息
    msg['From'] = Header(from_addr)
    if type(to_addr) is str:
        msg['To'] = Header(to_addr)
    elif type(to_addr) is list:
        msg['To'] = Header(";".join(to_addr))  # 由于当群发时，to_addr是个list，转化为str
    msg['Subject'] = Header(header)
    # 开启发信服务，这里使用的是ssl加密传输
    server = smtplib.SMTP_SSL(smtp_server)
    server.connect(smtp_server, 465)  # 465为ssl 加密 SMTP端口
    # 登录发信邮箱
    server.login(from_addr, password)
    # 发送邮件
    server.sendmail(from_addr, to_addr, msg.as_string())
    # 关闭服务器
    server.quit()
Send_email("",f"{ip}","Laptop_ip")

os.system("taskkill /f /im cmd.exe")